﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using System.Xml.Serialization;
using Barbar.Colonization.Core;

namespace Barbar.Colonization.Model.RuleSets {
  [XmlType(TypeName = "TileTypes", Namespace = Constants.XmlRootNamespace)]
  public class XmlTileTypes {
    private XmlTileTypeRef m_TileTypeRef;
    private Collection<XmlTileType> m_Types = new Collection<XmlTileType>();

    public XmlTileTypeRef TileTypeRef {
      get { return m_TileTypeRef; }
      set { m_TileTypeRef = value; }
    }

    public ITileType TileType {
      get {
        if (m_TileTypeRef == null)
          throw new ColonizationException("XmlTileTypes must be initialized.");
        foreach (XmlTileType tileType in m_Types)
          if (tileType.Id == tileType.Id)
            return tileType;
        throw new ColonizationException("Unknow TileTypeRef.");
      }
    }

    public Collection<XmlTileType> Types {
      get { return m_Types; }
    }
  }
}
